package com.tj.collection.controller.lending.response;

import com.fqgj.common.api.ResponseData;
import com.fqgj.common.utils.CollectionUtils;
import com.tj.collection.service.dto.DeviceContactDataVO;
import com.tj.collection.service.dto.DeviceContactVO;
import com.tj.collection.utils.IndiaMobileUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: pavan
 * Date: 2020/01/10
 * Time: 下午5:15
 */
public class ClDeviceContactDataResponse implements ResponseData {

    private Integer contactNum = 0;

    private Integer relationsNum = 0;

    private Integer exceptionNum = 0;

    private List<DeviceContactItem> list;

    private SelfItem contactSelfItem = new SelfItem();
    private SelfItem callSelfItem = new SelfItem();

    public ClDeviceContactDataResponse() {
    }

    public ClDeviceContactDataResponse(DeviceContactDataVO deviceContactData) {
        if (deviceContactData != null) {
            contactNum = deviceContactData.getTotalNum() == null ? 0 : deviceContactData.getTotalNum();
            relationsNum = deviceContactData.getRelativeNum() == null ? 0 : deviceContactData.getRelativeNum();
            exceptionNum = deviceContactData.getRiskNum() == null ? 0 : deviceContactData.getRiskNum();
            if (CollectionUtils.isNotEmpty(deviceContactData.getContacts())) {
                Integer key = 0;
                list = new ArrayList<>();
                for (DeviceContactVO deviceContact : deviceContactData.getContacts()) {
                    DeviceContactItem temp = new DeviceContactItem();
                    temp.setKey(key++);
                    temp.setName(deviceContact.getName());
                    temp.setPhone(IndiaMobileUtil.countryCodeFilter(deviceContact.getPhone()));
                    temp.setMobile(IndiaMobileUtil.countryCodeFilter(deviceContact.getPhone()));
                    temp.setLastCallTime(deviceContact.getCollectionLastContactTime());
                    temp.setLastCallDescribe(deviceContact.getCollectionLastContactTimeIntervalDays() == null ?
                            "" : (deviceContact.getCollectionLastContactTimeIntervalDays() + " days ago"));
                    temp.setCollectionContactRecord(deviceContact.getCollectionContactRecord());
                    temp.setState(deviceContact.getState())
                            .setIsRelation(deviceContact.getDeviceType());
                    list.add(temp);
                }
            }

            if (deviceContactData.getContactHitApplyMobile()) {
                contactSelfItem.setHit(true)
                        .setName(deviceContactData.getContactApplyMobileName() == null ? "" : deviceContactData.getContactApplyMobileName());
            }
            if (deviceContactData.getCallHitApplyMobile()) {
                callSelfItem.setHit(true)
                        .setName(deviceContactData.getCallApplyMobileName() == null ? "" : deviceContactData.getCallApplyMobileName());
            }
        }
    }


    private class DeviceContactItem {
        private Integer key;
        /**
         * 通讯录姓名
         */
        private String name;
        /**
         * 手机号码
         */
        private String phone;
        /**
         * 手机号码
         */
        private String mobile;
        /**
         * 催收最近一次联系时间
         */
        private String lastCallTime;
        /**
         * 催收最近一次联系时间 是在多少天之前
         */
        private String lastCallDescribe;
        /**
         * 催收备注
         */
        private String collectionContactRecord;
        /**
         * 催收标记的状态
         */
        private String state;

        private Integer isRelation = 0;

        public Integer getIsRelation() {
            return isRelation;
        }

        public DeviceContactItem setIsRelation(Integer isRelation) {
            this.isRelation = isRelation;
            return this;
        }

        public Integer getKey() {
            return key;
        }

        public DeviceContactItem setKey(Integer key) {
            this.key = key;
            return this;
        }

        public String getName() {
            return name;
        }

        public DeviceContactItem setName(String name) {
            this.name = name;
            return this;
        }

        public String getPhone() {
            return phone;
        }

        public DeviceContactItem setPhone(String phone) {
            this.phone = phone;
            return this;
        }

        public String getMobile() {
            return mobile;
        }

        public DeviceContactItem setMobile(String mobile) {
            this.mobile = mobile;
            return this;
        }

        public String getLastCallTime() {
            return lastCallTime;
        }

        public DeviceContactItem setLastCallTime(String lastCallTime) {
            this.lastCallTime = lastCallTime;
            return this;
        }

        public String getLastCallDescribe() {
            return lastCallDescribe;
        }

        public DeviceContactItem setLastCallDescribe(String lastCallDescribe) {
            this.lastCallDescribe = lastCallDescribe;
            return this;
        }

        public String getCollectionContactRecord() {
            return collectionContactRecord;
        }

        public DeviceContactItem setCollectionContactRecord(String collectionContactRecord) {
            this.collectionContactRecord = collectionContactRecord;
            return this;
        }

        public String getState() {
            return state;
        }

        public DeviceContactItem setState(String state) {
            this.state = state;
            return this;
        }
    }

    private class SelfItem {
        private Boolean hit = false;//是否含有申请人本人的号码吗
        private String name;

        public Boolean getHit() {
            return hit;
        }

        public SelfItem setHit(Boolean hit) {
            this.hit = hit;
            return this;
        }

        public String getName() {
            return name;
        }

        public SelfItem setName(String name) {
            this.name = name;
            return this;
        }
    }

    public Integer getContactNum() {
        return contactNum;
    }

    public ClDeviceContactDataResponse setContactNum(Integer contactNum) {
        this.contactNum = contactNum;
        return this;
    }

    public Integer getRelationsNum() {
        return relationsNum;
    }

    public ClDeviceContactDataResponse setRelationsNum(Integer relationsNum) {
        this.relationsNum = relationsNum;
        return this;
    }

    public Integer getExceptionNum() {
        return exceptionNum;
    }

    public ClDeviceContactDataResponse setExceptionNum(Integer exceptionNum) {
        this.exceptionNum = exceptionNum;
        return this;
    }

    public List<DeviceContactItem> getList() {
        return list;
    }

    public ClDeviceContactDataResponse setList(List<DeviceContactItem> list) {
        this.list = list;
        return this;
    }

    public SelfItem getContactSelfItem() {
        return contactSelfItem;
    }

    public ClDeviceContactDataResponse setContactSelfItem(SelfItem contactSelfItem) {
        this.contactSelfItem = contactSelfItem;
        return this;
    }

    public SelfItem getCallSelfItem() {
        return callSelfItem;
    }

    public ClDeviceContactDataResponse setCallSelfItem(SelfItem callSelfItem) {
        this.callSelfItem = callSelfItem;
        return this;
    }

}
